package com.navid.trafalgar.games;

import com.jme3.app.Application;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;
import com.jme3.system.JmeSystem;
import com.navid.trafalgar.definition.JsonAssetLoader;
import de.lessvoid.nifty.Nifty;


public class Main extends Application {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void start(JmeContext.Type contextType) {
        
        settings = new AppSettings(true);
        if (!JmeSystem.showSettingsDialog(settings, true)) {
            return;
        }
        
        //settings.setRenderer(AppSettings.LWJGL_OPENGL1);
        
        setSettings(settings);
        super.start(contextType);
    }

    @Override
    public void initialize() {
        super.initialize();
        
        assetManager.registerLoader( JsonAssetLoader.class, "json");

        super.setPauseOnLostFocus(false);
        
        MyStartScreen startScreen = new MyStartScreen(settings, this);
        Millestone2 millestoneScreen2 = new Millestone2(settings);
        stateManager.attach(startScreen);
        stateManager.attach(millestoneScreen2);

        /**
         * Activate the Nifty-JME integration: 
         */
        NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
                assetManager, inputManager, audioRenderer, guiViewPort);
        Nifty nifty = niftyDisplay.getNifty();
        guiViewPort.addProcessor(niftyDisplay);
        nifty.fromXml("Interface/interface.xml", "start", startScreen, millestoneScreen2);
    }

   @Override
    public void update() {
        // necessary stuff
        super.update();
        
        // do some animation
        float tpf = timer.getTimePerFrame();
        
        // update elements in all enabled states.
        stateManager.update(tpf);
        stateManager.render(renderManager);
       
        // render the viewports
        renderManager.render(tpf, context.isRenderable());
    }

    public String getPlayerName() {
        return System.getProperty("user.name");
    }
}
